#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;
int a, b;
bool suShu(int a)
{
    if (a == 2)
        return true;
    for (int i = 2; i <= sqrt(a); i++)
    {
        if (a % i == 0)
        {
            return false;
        }
    }
    return true;
}
bool huiWenShu(int x)
{
    int a[20];
    int flag = 1;
    while (x > 0)
    {
        a[flag] = x % 10;
        x /= 10;
        flag++;
    }
    for (int i = 1; i <= flag / 2; i++)
    {
        if (a[i] != a[flag - i])
        {
            return false;
        }
    }
    return true;
}
bool weiShu(int b)
{
    if ((1000 <= b && b <= 9999) || (100000 <= b && b <= 999999))
    {
        return false;
    }
    return true;
}
int main()
{
    cin >> a >> b;
    if (a == 2)
        cout << 2 << endl;
    if (a % 2 == 0)
        a++;
    if (b > 9999999)
    {
        b = 9999999;
    }
    for (int i = a; i <= b; i = i + 2)
    {
        if (!weiShu(i))
        {
            continue;
        }
        if (!huiWenShu(i))
        {
            continue;
        }
        if (!suShu(i))
        {
            continue;
        }
        printf("%d\n", i);
        /*
        if (i % 2 == 0 && i != 2)
        {

            continue;
        }
        if (suShu(i))
        {

            printf("%d\n", i);
            //cout << i << endl;
        }
        */
        /*
        if (i % 2 == 0 && i != 2)
        {
            i++;
            continue;
        }
        if (suShu(i))
        {
            if (i < 10)
            {
                cout << i << endl;
                i++;
                continue;
            }
            if (huiWenShu(i))
            {
                cout << i << endl;
            }
        }
        */
    }
}